﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RefactoringTechniques
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            CodeSmellGroups.Items.Add("Bloaters");
            CodeSmellGroups.Items.Add("Object-Orientation Abusers");
            CodeSmellGroups.Items.Add("Change Preventers");
            CodeSmellGroups.Items.Add("Dispensables");
            CodeSmellGroups.Items.Add("Couplers");
        }

        private void HandleSelectionChange(object sender, EventArgs e)
        {
            ComboBox sorz = (ComboBox)sender;
            if (sorz.Equals(CodeSmellGroups))
            {
                if(CodeSmellGroups.Text == "Bloaters")
                {
                    CodeSmells.Items.Clear();
                    Refactorings.Items.Clear();
                    CodeSmells.Text = string.Empty;
                    CodeSmells.Items.Add(string.Empty);
                    CodeSmells.Items.Add("Long Method");
                    CodeSmells.Items.Add("Large Class");
                    CodeSmells.Items.Add("Primitive Obsession");
                    CodeSmells.Items.Add("Long Parameter List");
                    CodeSmells.Items.Add("DataClumps");
                }
                else if(CodeSmellGroups.Text == "Object-Orientation Abusers")
                {
                    CodeSmells.Items.Clear();
                    Refactorings.Items.Clear();
                    CodeSmells.Text = string.Empty;
                    CodeSmells.Items.Add(string.Empty);
                    CodeSmells.Items.Add("Switch Statements");
                    CodeSmells.Items.Add("Temporary Field");
                    CodeSmells.Items.Add("Refused Request");
                    CodeSmells.Items.Add("Alternative Class with Different Interface");
                }
                else if(CodeSmellGroups.Text == "Change Preventers")
                {
                    CodeSmells.Items.Clear();
                    Refactorings.Items.Clear();
                    CodeSmells.Text = string.Empty;
                    CodeSmells.Items.Add(string.Empty);
                    CodeSmells.Items.Add("Divergent Change");
                    CodeSmells.Items.Add("Shotgun Surgery");
                    CodeSmells.Items.Add("Parallel Inheritance Hierarchies");
                }
                else if(CodeSmellGroups.Text == "Dispensables")
                {
                    CodeSmells.Items.Clear();
                    Refactorings.Items.Clear();
                    CodeSmells.Text = string.Empty;
                    CodeSmells.Items.Add(string.Empty);
                    CodeSmells.Items.Add("Lazy Class");
                    CodeSmells.Items.Add("Data Class");
                    CodeSmells.Items.Add("Duplicate Code");
                    CodeSmells.Items.Add("Dead Code");
                    CodeSmells.Items.Add("Speculative Generality");
                }
                else if(CodeSmellGroups.Text == "Couplers")
                {
                    CodeSmells.Items.Clear();
                    Refactorings.Items.Clear();
                    CodeSmells.Text = string.Empty;
                    CodeSmells.Items.Add(string.Empty);
                    CodeSmells.Items.Add("Feature Envy");
                    CodeSmells.Items.Add("Inappropriate Intimacy");
                    CodeSmells.Items.Add("Message Chains");
                    CodeSmells.Items.Add("Middle Man");
                }
            }
            else if (sorz.Equals(CodeSmells))
            {
                if (CodeSmellGroups.Text == "Bloaters")
                {
                    if (CodeSmells.Text == "Long Method")
                    {
                        Refactorings.Items.Clear();
                        Refactorings.Items.Add("Extract Method");
                        Refactorings.Items.Add("Introduce Parameter Object");
                        Refactorings.Items.Add("Decompose Conditional If");
                        Refactorings.Items.Add("Preserve Whole Object");
                        Refactorings.Items.Add("Replace Method with Method Object");
                        Refactorings.Items.Add("Replace Temp with Query");
                    }
                    else if (CodeSmells.Text == "Large Class")
                    {
                        Refactorings.Items.Clear();
                        Refactorings.Items.Add("Extract Class");
                        Refactorings.Items.Add("Extract Subclass");
                        Refactorings.Items.Add("Extract Interface");
                        Refactorings.Items.Add("Replace Data Value with Object");
                    }
                    else if (CodeSmells.Text == "Primitive Obsession")
                    {
                        Refactorings.Items.Clear();
                        Refactorings.Items.Add("Replace Data Value with Objects");
                        Refactorings.Items.Add("Introduce Parameter Object");
                        Refactorings.Items.Add("Extract Class");
                        Refactorings.Items.Add("Replace Type Code with Class");
                        Refactorings.Items.Add("Replace Type Code with Subclass");
                        Refactorings.Items.Add("Replace Array with Object");
                    }
                    else if (CodeSmells.Text == "Long Parameter List")
                    {
                        Refactorings.Items.Clear();
                        Refactorings.Items.Add("Replace Parameter with Method");
                        Refactorings.Items.Add("Introduce Parameter Object");
                        Refactorings.Items.Add("Preserve Whole Object");
                    }
                    else if (CodeSmells.Text == "DataClumps")
                    {
                        Refactorings.Items.Clear();
                        Refactorings.Items.Add("Extract Class");
                        Refactorings.Items.Add("Preserve Whole Object");
                        Refactorings.Items.Add("Introduce Parameter Object");
                    }
                }
                else if (CodeSmellGroups.Text == "Object-Orientation Abusers")
                {
                    if (CodeSmells.Text == "Switch Statements")
                    {
                        Refactorings.Items.Clear();
                        Refactorings.Items.Add("Replace Conditional with Polymorphism");
                        Refactorings.Items.Add("Replace Type Code with Subclass");
                        Refactorings.Items.Add("Replace Type Code with State/Strategy");
                        Refactorings.Items.Add("Replace Parameter with Explicit Methods");
                    }
                    else if (CodeSmells.Text == "Temporary Field")
                    {
                        Refactorings.Items.Clear();
                        Refactorings.Items.Add("Extract Class");
                    }
                    else if (CodeSmells.Text == "Refused Request")
                    {
                        Refactorings.Items.Clear();
                        Refactorings.Items.Add("Push Down Field");
                        Refactorings.Items.Add("Push Down Method");
                        Refactorings.Items.Add("Replace Inheritance with Delegation");
                    }
                    else if (CodeSmells.Text == "Alternative Class with Different Interface")
                    {
                        Refactorings.Items.Clear();
                        Refactorings.Items.Add("Rename Method");
                        Refactorings.Items.Add("Move Method");
                    }
                }
                else if (CodeSmellGroups.Text == "Change Preventers")
                {
                    if (CodeSmells.Text == "Divergent Change")
                    {
                        Refactorings.Items.Clear();
                        Refactorings.Items.Add("Extract Class");
                    }
                    else if (CodeSmells.Text == "Shotgun Surgery")
                    {
                        Refactorings.Items.Clear();
                        Refactorings.Items.Add("Move Method");
                        Refactorings.Items.Add("Move Field");
                        Refactorings.Items.Add("Inline Class");
                    }
                    else if (CodeSmells.Text == "Parallel Inheritance Hierarchies")
                    {
                        Refactorings.Items.Clear();
                        Refactorings.Items.Add("Move Method");
                        Refactorings.Items.Add("Move Field");
                    }
                }
                else if (CodeSmellGroups.Text == "Dispensables")
                {
                    if (CodeSmells.Text == "Lazy Class")
                    {
                        Refactorings.Items.Clear();
                        Refactorings.Items.Add("Collapse Hierarchy");
                        Refactorings.Items.Add("Inline Class");
                        Refactorings.Items.Add("Inline Singleton");
                    }
                    else if (CodeSmells.Text == "Data Class")
                    {
                        Refactorings.Items.Clear();
                        Refactorings.Items.Add("Move Method");
                        Refactorings.Items.Add("Encapsulate Field");
                        Refactorings.Items.Add("Encapsulate Collection");
                    }
                    else if (CodeSmells.Text == "Duplicate Code")
                    {
                        Refactorings.Items.Clear();
                        Refactorings.Items.Add("Extract Method");

                    }
                    else if (CodeSmells.Text == "Dead Code")
                    {
                        Refactorings.Items.Clear();
                        Refactorings.Items.Add("Source Control");
                        Refactorings.Items.Add("Delete It");
                    }
                    else if (CodeSmells.Text == "Speculative Generality")
                    {
                        Refactorings.Items.Clear();
                        Refactorings.Items.Add("Collapse Hierarchy");
                        Refactorings.Items.Add("Rename Method");
                        Refactorings.Items.Add("Remove Parameter");
                        Refactorings.Items.Add("Inline Class");
                    }
                }
                else if (CodeSmellGroups.Text == "Couplers")
                {
                    if (CodeSmells.Text == "Feature Envy")
                    {
                        Refactorings.Items.Clear();
                        Refactorings.Items.Add("Extract Method");
                        Refactorings.Items.Add("Move Method");
                        Refactorings.Items.Add("Move Field");
                    }
                    else if (CodeSmells.Text == "Inappropriate Intimacy")
                    {
                        Refactorings.Items.Clear();
                        Refactorings.Items.Add("Move Method");
                        Refactorings.Items.Add("Move Field");
                        Refactorings.Items.Add("Change Bidirectional Association to Unidirectional Association");
                        Refactorings.Items.Add("Extract Class");
                        Refactorings.Items.Add("Extract Delegate");
                        Refactorings.Items.Add("Replace Inheritance with Delegation");
                    }
                    else if (CodeSmells.Text == "Message Chains")
                    {
                        Refactorings.Items.Clear();
                        Refactorings.Items.Add("Hide Delegate");
                        Refactorings.Items.Add("Extract Method");
                        Refactorings.Items.Add("Move Method");
                    }
                    else if (CodeSmells.Text == "Middle Man")
                    {
                        Refactorings.Items.Clear();
                        Refactorings.Items.Add("Remove Middle Man");
                        Refactorings.Items.Add("Inline Method");
                        Refactorings.Items.Add("Replace Delegation with Inheritance");
                    }
                }
            }
        }
    }
}
